package com.sevice;

import org.springframework.stereotype.Service;

import java.util.*;

/**
 * 双色球
 *
 * @author yuanqinglong
 * @since 2021/12/16 17:27
 */
@Service
public class TwoColorBall extends AbstractLottery {
    private static final List<String> RED_BALL = new ArrayList<>();
    private static final List<String> BLUE_BALL = new ArrayList<>();

    static {
        for (int i = 1; i <= 33; i++) {
            RED_BALL.add(i < 10 ? "0" + i : String.valueOf(i));
        }
        for (int i = 1; i <= 16; i++) {
            BLUE_BALL.add(i < 10 ? "0" + i : String.valueOf(i));
        }
    }


    @Override
    public int checkRedAmount(int redNumber) {
        return redNumber > 33 ? 33 : Math.max(redNumber, 6);
    }

    @Override
    public int checkBlueAmount(int blueNumber) {
        return blueNumber > 16 ? 16 : Math.max(blueNumber, 1);
    }

    @Override
    void consumption() {
        int combination = C(numberOfRed, 6) * C(numberOfBlue, 1);
        int money = combination * multiple * votes << 1;
        System.out.println("共：" + combination * votes + "注，消费：" + money + "元");
    }

    @Override
    List<String> getRedBallList() {
        Collections.shuffle(RED_BALL);
        return RED_BALL;
    }

    @Override
    List<String> getBlueBallList() {
        Collections.shuffle(BLUE_BALL);
        return BLUE_BALL;
    }

    @Override
    void betting(Scanner scanner, int howToPlay) {
        if (howToPlay == 1 || howToPlay > 2) {
            numberOfRed = 6;
            numberOfBlue = 1;
        } else {
            System.out.print("选几个红球[6~33]:");
            numberOfRed = this.checkRedAmount(scanner.nextInt());
            System.out.print("选几个蓝球[1~16]:");
            numberOfBlue = this.checkBlueAmount(scanner.nextInt());
        }
        System.out.print("买几注：");
        votes = scanner.nextInt();
        System.out.print("买几倍：");
        multiple = scanner.nextInt();
    }

}
